<template>
    <div>
        <h1>会员等级添加</h1>
        <table class="table">
            <thead>
                <tr>
                    <td>权益名称</td>
                    <td><input type="text" v-model="data.QYName"></td>
                </tr>
                <tr>
                    <td>权益状态</td>
                    <td>
                        <input type="radio" name="QYState" :value="'true'" v-model="data.QYState">启用
                        <input type="radio" name="QYState" :value="'false'" v-model="data.QYState">禁用
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="button" value="新增" @click="Add"></td>
                </tr>
            </thead>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref ,onMounted} from 'vue';
import axios from 'axios';
import { useRouter,useRoute } from 'vue-router';
onMounted(()=>{
    Fan()
})
const router = useRouter()

const route = useRoute();
//反填
const Fan=()=>{
    var c = route.query.QYId;
    axios.get('https://localhost:7174/api/QY/FanMember',{params:{QYId:c}}).then(res=>{
        data.value = res.data;
    })
}



//新增
const data = ref({
   "QYId": 0,
  "QYName": "",
  "QYState": true,
  "QYIsDelete": true
})

const Add=()=>{
    if(data.value.QYName==""){
        alert('权益名称不能为空')
        return
    }
    axios.post('https://localhost:7174/api/QY/UpdMember',data.value).then(res=>{
        if(res.data>0){
            alert('修改成功');
            router.push({path:"/QYShow"})
        }
        else{
            alert('修改失败')
        }
    })
}







</script>

<style scoped>

</style>